home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
magazine
/
drdobbs
/
1987
/
12
/
tracy
/
trcy.exp
< prev
Wrap
Text File
|
1987-11-13
|
2KB
|
109 lines
( Moves NEXT address to and from stack.)
: I> ( - a) COMPILE R> ; IMMEDIATE
: >I ( a ) COMPILE >R ; IMMEDIATE
( Even address alignment, if required.)
: ALIGN HERE 1 AND ALLOT ;
: REALIGN ( a - a') DUP 1 AND + ;
( Hides number of bytes per word.)
2 CONSTANT CELL
: CELL+ ( n - n') 2+ ;
: CELLS ( n - n') 2* ;
( Compiles self-reference.)
: RECURSE ( ...) ; IMMEDIATE
( Forces interpretation of the input stream.)
: INTERPRET ( ...) ;
( Discards return stack overhead of DO--LOOP.)
: UNDO I> R> R> 2DROP >I ;
example 1
NEED D2* \IF : D2* ( d - d') 2DUP D+ ;
NEED HEX \IF : HEX ( DECIMAL ) 10 BASE ! ;
NEED C, \IF : C, ( n ) HERE 1 ALLOT C! ;
NEED BL \IF 32 CONSTANT BL ( a blank)
NEED ERASE \IF : ERASE ( a n) 00 FILL ;
NEED BLANK \IF : BLANK ( a n) BL FILL ;
NEED .R \IF : .R ( n w) >R DUP 0< R> D.R ;
EXAMPLE 2
: 2>R ( n n2)
\ pushes a pair on the return stack.
COMPILE SWAP COMPILE >R COMPILE >R ;
IMMEDIATE
: 2R> ( - n n2)
\ pops a pair from the return stack.
COMPILE R> COMPILE R> COMPILE SWAP ;
IMMEDIATE
: @EXECUTE ( ? ) @ EXECUTE ;
: AGAIN
\ used in a BEGIN-- AGAIN structure.
0 [COMPILE] LITERAL [COMPILE] UNTIL ;
IMMEDIATE
: DLITERAL SWAP
[COMPILE] LITERAL [COMPILE] LITERAL ;
IMMEDIATE
: S>D ( n - d) DUP 0< ;
\ single to double number.
: WITHIN ( n min max - f)
\ true if min <= n < max.
OVER - >R - R> U< ;
-1 CONSTANT TRUE
example 3
-TEXT ( a n a2 - -1 , 0 , 1)
\ -1 if string a n < a2 n , 0 if equal,
\ and 1 if >.
COMPARE ( a n a2 n2 - -1 , 0 , 1)
\ -1 if string a n < a2 n2 , 0 if equal,
\ and 1 if >.
-MATCH ( a n a2 n2 - offset 0 , ? -1)
\ position of string a2 n2 in a n.
\ Offset is 0 if a n is found in 1st
\ position. True with invalid offset
\ if a2 n2 isn't in a n.
: ANIMAL " ANIMAL" ;
" ANIMATE" ANIMAL COMPARE . 1 ok
" ANT" ANIMAL COMPARE . -1 ok
ANIMAL " IMA" -MATCH . . 0 2 ok
ANIMAL " XYZ" -MATCH . . -1 ????? ok
example 4